﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Duality;
using Duality.Components;

using OpenTK;

namespace MagicPrototype.TestStuff
{
	[Serializable]
	[RequiredComponent(typeof(Camera))]
    public class CameraController : Component, ICmpUpdatable
    {
		private GameObject	followTarget	= null;
		private Vector3		followOffset	= new Vector3(0, 0, -500);

		public GameObject FollowTarget
		{
			get { return this.followTarget; }
			set { this.followTarget = value; }
		}
		public Vector3 FollowOffset
		{
			get { return this.followOffset; }
			set { this.followOffset = value; }
		}

		void ICmpUpdatable.OnUpdate()
		{
			Transform transform = this.GameObj.Transform;
			Transform targetTransform = this.followTarget != null ? this.followTarget.Transform : null;
			if (targetTransform == null) return;

			transform.MoveByAbs((targetTransform.Pos + this.followOffset - transform.Pos) * 0.1f * Time.TimeMult);
		}
	}
}
